package org.liufeng.weixin.main;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.liufeng.weixin.pojo.AccessToken;  
import org.liufeng.weixin.pojo.Button;  
import org.liufeng.weixin.pojo.CommonButton;  
import org.liufeng.weixin.pojo.ComplexButton;  
import org.liufeng.weixin.pojo.Menu;  
import org.liufeng.weixin.util.WeixinUtil;  
import org.slf4j.Logger;  
import org.slf4j.LoggerFactory;  


import com.thoughtworks.xstream.XStream;


  
/** 
 * 菜单管理器类 
 *  
 * @author liufeng 
 * @date 2013-08-08 
 */  
public class FileManager {  
    private static Logger log = LoggerFactory.getLogger(FileManager.class);  
	private XStream xstream = null;
    private ObjectOutputStream  out = null;
    private ObjectInputStream in = null;
    public static void main(String[] args) {  

    }
    

    @Before    
    public void init() {        
        try {            
        		xstream = new XStream();
        		//xstream = new XStream(new DomDriver());
        		// 需要xpp3 jar        
        	} catch (Exception e) {            
        		e.printStackTrace();
        }       

 
    }        
    /**     
     * * <b>function:</b>释放对象资源     * 
     * @author hoojo     * 
     * @createDate Nov 27, 2010 12:16:38 PM     */    
    
    @After    
    public void destory() {        
        xstream = null;

        try {            
        	if (out != null) {                
        		out.flush();
                out.close();
            }            
        	if (in != null) {                
        		in.close();
            }       
        } catch (IOException e) {           
        	e.printStackTrace();
        }        
        System.gc();
    }
        
    @Test
    public void uploadFile (){
    	System.out.println("-------------upload media------------");
        // 第三方用户唯一凭证   
        String appId = "wxb646688880f54ca8";  
        // 第三方用户唯一凭证密钥   
        String appSecret = "f83ee621b022433097ace94a19543661";  
  
        // 调用接口获取access_token   
        AccessToken at = WeixinUtil.getAccessToken(appId, appSecret);  
  
        if (null != at) {  
            // 调用接口创建菜单   
            int result = WeixinUtil.uploadFile(at.getToken());  
        	
            // 判断菜单创建结果   
            if (0 == result)  
            	System.out.println("上传创建成功！");  
            else  
            	System.out.println("上传失败，错误码：" + result);  
        }  
        
    }
    
    
    public static void failRed(String string)  {        
    	System.err.println(string);
    }
    public static void fail(String string) {        
    	System.out.println(string);
    }        
        
}